package toman;

import toman.jdbc.MapResultSetQuery;

import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.List;

/**
 * User: zslajchrt
 * Date: 2.5.11
 * Time: 15:25
 */
public class PhotoFilterEngine extends EngineForCreatingQueriesOnly {

    private final DataSource ds;

    public PhotoFilterEngine(DataSource ds) {
        this.ds = ds;
    }

    public <T> boolean canCreateQuery(TOMan toman, Class<T> toClass, Object queryDefinition) {
        return queryDefinition instanceof PhotoFilter;
    }

    public <T> TOQuery<T> createQuery(final TOMan toMan, final Class<T> toCls, Object queryDefinition) throws Exception {
        final PhotoFilter filter = (PhotoFilter) queryDefinition;
        List<Object> params = new ArrayList<Object>();
        String sql = filter.getSQL(params);
        return new MapResultSetQuery<T>(sql, toCls, toMan, ds, params);
    }
}
